package com.myacg.editor.common.unit.list.item;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;

import javax.swing.JLabel;
import javax.swing.JPanel;

import com.myacg.editor.common.entity.CoupleDao;
/**
 * 左右居中结构的listItem
 * @author Administrator
 *
 */
public class CoupleDataListItem extends FlowListItem<CoupleDao>{
	private JLabel title ;
	private JLabel content ;
	private JPanel titlePanel ;
	private JPanel contentPanel ;
	private int maxWidth;
	public CoupleDataListItem(String id, CoupleDao data) {
		super(id, data);
		title  = new JLabel(data.getName());
		content = new JLabel(data.getValue());
		initDefault();
	}
	
	private void initDefault(){
		this.removeAll();
		titlePanel = new JPanel(new  FlowLayout(2,5,5));
		contentPanel = new JPanel(new  FlowLayout(0,5,5));
		titlePanel.add(title);
		contentPanel.add(content); 
		titlePanel.setOpaque(false);
		contentPanel.setOpaque(false);
		this.setOpaque(false);
		this.setLayout(new BorderLayout());
		this.add(titlePanel,BorderLayout.WEST);
		this.add(contentPanel,BorderLayout.CENTER);
	}
	private void initUpper(){
		this.removeAll();
		titlePanel = new JPanel(new  FlowLayout(0,5,0));
		contentPanel = new JPanel(new  FlowLayout(1,5,0));
		titlePanel.add(title);
		contentPanel.add(content); 
		titlePanel.setOpaque(false);
		contentPanel.setOpaque(false);
		this.setOpaque(false);
		this.setLayout(new BorderLayout());
		this.add(titlePanel,BorderLayout.NORTH);
		this.add(contentPanel,BorderLayout.CENTER);
	}
	
	@Override
	public void setSelected(boolean selected) {
		super.setSelected(selected);
	}
	@Override
	public void drawContent(Graphics g,CoupleDao data) {
		if(this.maxWidth == 0){
			this.maxWidth = this.getWidth();
			this.titlePanel.setPreferredSize(new Dimension(maxWidth/2, this.titlePanel.getHeight()));
			this.contentPanel.setPreferredSize(new Dimension(maxWidth/2, this.contentPanel.getHeight()));
		}
		this.content.setText(data.getValue());
	}
}
